package cn.pengyinrui.department.utils;

import lombok.Data;

@Data
public class AjaxResult {
    private String tip;// 提示
    private Boolean state;// 状态
    private Object data;// 数据
    private Long total;// 数据数量
    // 构造方法私有化，单例模式
    private AjaxResult() {
    }
    private AjaxResult(String tip, Boolean state) {
        this.tip = tip;
        this.state = state;
    }
    // 成功
    public static AjaxResult success() {
        return new AjaxResult("操作成功",true);
    }
    // 失败
    public static AjaxResult error() {
        return new AjaxResult("操作失败",false);
    }
    // 链式编程
    public AjaxResult setTip(String tip) {
        this.tip = tip;
        return this;
    }

    public AjaxResult setState(Boolean state) {
        this.state = state;
        return this;
    }

    public AjaxResult setData(Object data) {
        this.data = data;
        return this;
    }

    public AjaxResult setTotal(Long total) {
        this.total = total;
        return this;
    }
}
